<template>
  <div class="home">
    <el-container>
        <el-header>
            <div>
              <img class="header-img" src="../assets/logo.png" alt="">
              <span>电商管理系统</span>
            </div>
            <el-button class="btn-exit-login" type="danger"  @click="exit">退出系统</el-button>
        </el-header>
        <el-container>
            <el-aside :width="isCollapse ? '64px': '200px'">
              <div class="toggleCollapse" @click="toggleCollapse">|||</div>
              <el-menu default-active="2" class="el-menu-vertical-demo"
               background-color="#333744" text-color="#fff" active-text-color="#409eff"
               unique-opened :collapse="isCollapse" :collapse-transition="false"
               router :defaultActive="activitePath">
                <el-submenu :index="item.id+''" :key='item.id' v-for='item in mentLis' >
                  <template slot="title">
                    <i :class="iconsObj[item.id]"></i>
                    <span>{{item.authName}}</span>
                  </template>
                  <el-menu-item :index="'/'+subItem.path"
                    :key='subItem.id' v-for='subItem in item.children'
                    @click="saveNavState('/'+subItem.path)">
                    <template slot="title">
                      <i class="el-icon-menu"></i>
                      <span>{{subItem.authName}}</span>
                    </template>
                  </el-menu-item>
                </el-submenu>
              </el-menu>
            </el-aside>
            <el-main>
              <router-view></router-view>
            </el-main>
        </el-container>
        <el-footer>footer</el-footer>
    </el-container>
  </div>
</template>

<script>
export default {
  data () {
    return {
      mentLis: [],
      iconsObj: {
        '125': 'iconfont icon-user',
        '103': 'iconfont icon-tijikongjian',
        '101': 'iconfont icon-shangpin',
        '102': 'iconfont icon-danju',
        '145': 'iconfont icon-baobiao'
      },
      isCollapse: false,
      activitePath: ''
    }
  },
  created () {
    this.getMenuList()
    this.activitePath = window.sessionStorage.getItem('activitePath')
  },
  methods: {
    exit () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async getMenuList () {
      // 请求左侧菜单的menuList
      let { data: res } = await this.$http.get('menus')
      this.mentLis = res.data
      // console.log(res.data)
    },
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    },
    saveNavState (path) {
      window.sessionStorage.setItem('activitePath', path)
      this.activitePath = path
    }
  }
}
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;
}
.home {
  height: 100%;
}
.header-img{
  height: 50px;
}
.el-header{
    height: 60px;
    background: #373d41;
    display: flex;
    justify-content: space-between;
    color: rgb(255, 255, 255);
    font-size: 20px;
    align-items: center;
    >div {
      display: flex;
      align-items: center;
      span {
        margin-left: 20px;
      }
    }
}
.el-footer {
    background-color: #373d41;
    color: #333;
    text-align: center;
    line-height: 50px;
}
.el-aside {
    background-color: #333744;
    >.el-menu{
      border-right: none
    }
}
.el-main {
    background-color: #E9EEF3;
    color: #333;
}
.iconfont {
  margin-right: 10px;
}
.toggleCollapse{
  background-color: #4a5064;
   font-size: 10px;
   line-height: 24px;
   color: #fff;
   text-align: center;
   letter-spacing: 0.2em;
}
</style>
